function fast(arr = [], left, right) {
    if (!arr.length) return [];
    if (left < right) {
        let i = left;
        let j = right;
        let mid = i; //Math.floor((left + right) / 2);
        let tmp = arr[mid];
        while (i < j) {
            while (i < j && tmp <= arr[j]) j--;
            if (i < j) arr[i] = arr[j];
            while (i < j && tmp >= arr[i]) i++;
            if (i < j) arr[j] = arr[i];
        }
        arr[i] = tmp;
        console.log(arr)
        fast(arr, left, i - 1);
        fast(arr, i + 1, right);
    }
}

/**
 * 基于数组操作的解决方案
 * @param {*} arr 
 * @returns 
 */
function quickSort(arr = []) {
    if (!arr.length) return [];
    let mid = arr[0];
    let left = [];
    let right = [];
    for (let i = 1; i < arr.length; i++) {
        if (mid > arr[i]) {
            left.push(arr[i]);
        } else {
            right.push(arr[i]);
        }
    }
    return [...quickSort(left), mid, ...quickSort(right)];
}

let arr1 = [2, 3, 1, 4, 78, 23, 45];
console.log("快速排序的js方法：", quickSort(arr1));